<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<html>
<head>
<title>_校对清单</title>
<script type="text/javascript">

    
     $(function() {
	      var status='${task.status}';
	      if(status=='undo' || status=='finish'){
		    $("[type=button]").attr("disabled", true);
		    $("[type=button]").attr("class", "btn");
	      }else{
		    $("[type=button]").attr("disabled", false);
	      }
     });

   //创建json对象  
   function createItem(id,salesNum,unusedNum,orderNum){
	    return {
	        id:id,
	        salesNum:salesNum,
	        unusedNum:unusedNum,
	        orderNum:orderNum
	    };
	}
	
	//完成任务
	function finish(){
	  var r=confirm("确定完成校对任务吗？");
	  if(r==false){
   		return;
      }else{
	        $.ajax({
				type:'post',
				url:'${ctx}/checkFixTask/ajaxFinish',
				data:{
				    taskCode:'${task.taskCode}'
				},
				dataType:'json',
				success:function(data) {
				    if(data==true){
				         location.href='${ctx}/checkFixTask/v2_queryTaskList';
				    }else{
				      alert("网络繁忙，请稍后重试...");
				    }
				},
				error:function() {
					alert("网络繁忙，请稍后重试...");
				}
		  });
      }
	}
	
	//冲正标识
	function reverse(itemId,reverseFlag){
	  var btn=$("#right_"+itemId);
	  btn.attr("disabled", true);
	  btn.attr("class", "btn");
	  var finishBtn = $("#finish_btn");
	  finishBtn.attr("disabled", true);
	  $.ajax({
			type:'post',
			url:'${ctx}/checkFixTask/ajaxReverse',
			data:{
			    itemId:itemId,
			    reverseFlag:reverseFlag
			},
			dataType:'json',
			success:function(data) {
			    if(data==true){
			       if(reverseFlag=='notreverse'){
			         btn.attr("onclick","reverse("+itemId+",'reverse')");
			         btn.attr('value','发起冲正');
			         btn.attr("class", "btn btn-danger");
			         
			       }else if(reverseFlag=='reverse'){
			         btn.attr("onclick","reverse("+itemId+",'notreverse')");
			         btn.attr('value','取消冲正');
			         btn.attr("class", "btn btn-primary");
			       }
			    }else{
			       alert("网络繁忙，请稍后重试...");
			    }
			    btn.attr("disabled", false);
			    finishBtn.attr("disabled", false);
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
				btn.attr("disabled", false);
				finishBtn.attr("disabled", false);
			}
		});
	}
	


</script>
</head>

<body>
<section class="content">

   <!-- 校对明细 -->
   <div class="box box-solid box-primary" >
	      <div class="box-header">
			<i class="fa fa-th-large"></i>
			<h3 class="box-title">盘点校对</h3>
		 </div> 
	<div class="box-body" >
	
	<table id="stockCodeTable" class="table table-bordered table-condensed" >
		<thead><tr>
		    <th >序号</th>
		    <th >商家名称</th>
		    <th style="width: 100px;">仓库网点</th>
		    <th >库位编码</th>
		    <th >箱编码</th>
		    <th style="width: 130px;">SKU</th>
		    <th >批次号</th>
		    <th >生产日期</th>
		    <th >过期日期</th>
		    
		    <th style="width: 130px;">可销（库存/点数）</th>
		    <th style="width: 130px;">不可销（库存/点数）</th>
		    <th style="width: 150px;">订单占用（库存/点数）</th>
		    
		    <th style="width: 100px;" >可销售(校对)</th>
		    <th style="width: 100px;">不可销售(校对)</th>
		    <th style="width: 100px;">订单占用(校对)</th>
		    
		    <th style="width: 50px;">操作</th>
		    
		</tr></thead>
		
	    <c:forEach items="${itemList}" var="item" varStatus="i">
				<tr id="tr_${item.id}" >
				   <td>${i.count}</td>
				   <td>${item.customer.customerName}</td>
				   <td>${item.warehouse.groupName}</td>
				   <td>${item.stockCode}</td>
				   <td>${item.boxCode}</td>
				   <td>${item.sku}</td>
				   <td>${item.batchCode}</td>
				   <td>${item.productDate}</td>
				   <td>${item.expireDate}</td>
				   
				   <td>${item.salesNum}/${item.salesNumCheck}</td>
				   <td>${item.unusedNum}/${item.unusedNumCheck}</td>
				   <td>${item.orderNum}/${item.orderNumCheck}</td>
				   
				   <td style="background-color: #99CCF0;">
<!-- 				     <input type="hidden" name="itemData" id="${item.id}"> -->
<!-- 				     <input id="sales_${item.id}" type="text" value="${item.salesNumFix }" style="width: 70px;"/> -->
<!-- 				     <span  id='sales_msg_${item.id}' style='color:red;'></span> -->
						 ${item.salesNumFix }
				   </td>
				   <td style="background-color: #99CCF0;">
<!-- 				     <input id="unused_${item.id}" type="text" value="${item.unusedNumFix}" style="width: 70px;"/> -->
<!-- 				     <span   id='unused_msg_${item.id}' style='color:red;'></span> -->
						 ${item.unusedNumFix}
				   </td>
				    <td style="background-color: #99CCF0;">
<!-- 				     <input id="order_${item.id}" type="text" value="${item.orderNumFix}" readonly="readonly" style="width: 70px;"/> -->
<!-- 				     <span   id='order_msg_${item.id}' style='color:red;'></span> -->
                         ${item.orderNumFix}
				   </td>
				   
				   <td id="tr_right_${item.id}">
				      <c:if test="${ (item.reverseFlag eq 'need') or (item.reverseFlag eq 'notreverse') }">
				        <input id="right_${item.id}" type="button" class="btn btn-danger" onclick="reverse('${item.id}','reverse');" value="发起冲正"/>
				      </c:if>
				      
				      <c:if test="${item.reverseFlag eq 'reverse' }">
				        <input id="right_${item.id}" type="button" class="btn btn-primary" onclick="reverse('${item.id}','notreverse');" value="取消冲正"/>
				      </c:if>
				      
				   </td>
				</tr>
		</c:forEach>
	 
	 </table>
	</div></div>	

      	<div class="form-actions">
      	    <input id="finish_btn" class="btn btn-primary" type="button" value="完成校对" onclick="finish();" />
	    </div>
	    
</section>
</body>
</html>
